package com.javaAdmin.controller;

import cn.hutool.json.JSONUtil;
import com.javaAdmin.model.Admin;
import com.javaAdmin.server.AdminServer;
import com.javaAdmin.util.Result;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * @author Administrator
 */
@RestController
@RequestMapping("/redis/hash")
public class RedisHashController {

    @Resource
    private StringRedisTemplate stringRedisTemplate;

    @Resource
    private AdminServer adminServer;

    @GetMapping("/add")
    public void add() {
        //List<Admin> admins = adminServer.list();

        HashMap<String, Object> map = new HashMap<>();
        map.put("name", "admin");
        map.put("password", "123456");
        map.put("password1", "123456");
        map.put("password2", "123456");
        stringRedisTemplate.opsForHash().putAll("adminHash", map);
    }

    @GetMapping("/info")
    public List<Admin> info() {
        System.out.println("user：" + stringRedisTemplate.opsForHash().entries("adminHash"));


        System.out.println(stringRedisTemplate.opsForHash().keys("adminHash"));
        return null;
    }

    @GetMapping("/update")
    public void update() {
        stringRedisTemplate.opsForHash().put("adminHash", "name", "张三三111");
    }

    @GetMapping("/del")
    public void del() {

        boolean rs = stringRedisTemplate.delete("adminList");
        if (rs == true) {
            Result.success();
        } else {
            Result.fail();
        }
    }
}
